#include "CreditsState.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "../SGD Wrappers/SGD_InputManager.h"
#include "Menu.h"
#include "Game.h"
#include "MainMenuState.h"
#include "BitmapFont.h"

CreditsState* CreditsState::GetInstance()
{
	static CreditsState instance;
	return &instance;
}

void CreditsState::Enter()
{
	SGD::GraphicsManager::GetInstance()->SetClearColor({ 0, 0, 0 });
	menu = new Menu;
	menu->Initialize("resources/xml/credits.xml");
	background = SGD::GraphicsManager::GetInstance()->LoadTexture("resources/images/shadowmancer_menu.png");

}

void CreditsState::Exit()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(background);

	delete menu;
	menu = nullptr;
}

bool CreditsState::Input()
{
	if (SGD::InputManager::GetInstance()->IsKeyPressed(SGD::Key::Escape)
		|| SGD::InputManager::GetInstance()->IsButtonPressed(0, 1))
	{
		Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
		return true;
	}
	return true;
}

void CreditsState::Update(float elapsedTime)
{
	menu->Update(elapsedTime);
}

void CreditsState::Render()
{
	SGD::GraphicsManager::GetInstance()->DrawTexture(background, {}, {}, {}, {}, { 1, 1 });
	BitmapFont* font = Game::GetInstance()->GetFont();
	SGD::InputManager* input = SGD::InputManager::GetInstance();
	font->Draw("Credits", 5, 5, 1.0f, { 255, 255, 255 });
	menu->Render();
}